package com.satan.vote.controller;

import com.satan.vote.dto.VoteDTO;
import com.satan.vote.service.VoteItemService;
import com.satan.vote.service.VoteService;
import com.satan.vote.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @ClassName VoteController
 * @Description TODO
 * @date 2023/8/13 14:26
 * @Version 1.0
 */
@RestController
@RequestMapping("vote")
public class VoteController {
    @Autowired
    private VoteService voteService;
    @Autowired
    private VoteItemService voteItemServiceService;
    @RequestMapping("/uploadCoverImage")
    public ResultVO uploadCoverImage(MultipartFile coverImage){
            return voteService.uploadCoverImage(coverImage);
    }

    @RequestMapping("/uploadVoteItemImage")
    public ResultVO uploadVoteItemImage(MultipartFile voteItemImage) throws IOException {
        return voteItemServiceService.uploadVoteItemImage(voteItemImage);
    }

    @RequestMapping("/add")
    public ResultVO add(@RequestBody VoteDTO voteDTO, @RequestHeader String token){
        System.out.println("voteDTO = " + voteDTO);
        return  voteService.add(voteDTO,token);
    }
    /**
     * 获取指定用户创建的投票列表
     * @param token
     * @return
     */
    @RequestMapping("/listOfUser")
    public ResultVO listOfUser(@RequestHeader String token){

        return voteService.listOfUser(token);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResultVO findById(@PathVariable(value = "id") Integer id){
        return voteService.findById(id);
    }

    /**
     * 获取指定用户参与的投票
     * @param token
     * @return
     */
    @RequestMapping("/listOfJoinUser")
    public ResultVO listOfJoinUser(@RequestHeader String token){
       return   voteService.listOfJoinUser(token);
    }

    /**
     * 删除指定id的投票信息
     * @param id
     * @return
     */
    @GetMapping("/delete/{id}")
    public ResultVO delete(@PathVariable(value = "id")Integer id){
        return voteService.delete(id);
    }

}
